package cli

import (
	"fmt"
	"github.com/urfave/cli/v2"
	"miao-wails/backed/app/service"
	"os"
)

func main() {
	app := cli.NewApp()
	app.Name = "vap_host_cli"
	app.Usage = "主机配置插件"
	app.Flags = []cli.Flag{
		&cli.BoolFlag{
			Name: "getRdp",
			Action: func(ctx *cli.Context, b bool) error {
				port, err := service.VapServ.GetRdpPort()
				if err != nil {
					return cli.Exit(fmt.Sprintf("GetRdpPort err:%s", err), 1)
				}
				fmt.Println(port)
				return nil
			},
		},
		&cli.IntFlag{
			Name: "setRdp",
			Action: func(ctx *cli.Context, port int) error {
				err := service.VapServ.SetRdpPort(port)
				if err != nil {
					return cli.Exit(fmt.Sprintf("SetRdpPort err:%s", err), 1)
				}
				fmt.Println(port)
				return nil
			},
		},

		&cli.BoolFlag{
			Name: "getStartType",
			Action: func(ctx *cli.Context, b bool) error {
				t, err := service.VapServ.GetConfigForStartType()
				if err != nil {
					return cli.Exit(fmt.Sprintf("GetConfigForStartType err:%s", err), 1)
				}
				fmt.Println(t)
				return nil
			},
		},
		&cli.BoolFlag{
			Name: "setStartType",
			Action: func(ctx *cli.Context, b bool) error {
				err := service.VapServ.SetConfigForStartType(b)
				if err != nil {
					return cli.Exit(fmt.Sprintf("SetConfigForStartType err:%s", err), 1)
				}
				return nil
			},
		},
	}

	app.Action = func(ctx *cli.Context) error {
		return nil
	}
	if err := app.Run(os.Args); err != nil {
		fmt.Println("调用命令行时发生错误：", err.Error())
		return
	}
}
